import { JSEncrypt } from 'jsencrypt'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey =
  'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMJaq+rqliaQe7/rHKPsf/ciPMHlCksF\n' +
  'KQ75CfRyyKBoxqSc4sWGfcALrFSZbUCt2E3YqM1AZ7cs8JsfLh4wkHECAwEAAQ=='

const privateKey =
  'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAwlqr6uqWJpB7v+sc\n' +
  'o+x/9yI8weUKSwUpDvkJ9HLIoGjGpJzixYZ9wAusVJltQK3YTdiozUBntyzwmx8u\n' +
  'HjCQcQIDAQABAkAxRFTSLvcy/WsxQkM3Vos1tWsbZ5kNXViEICMi4Tn0V0nHry9E\n' +
  'G/fTVmYKcNf8t9RCUEQts+1BIFjGtx85JevFAiEA6+kSf5+q11s2ZKwsdsLE5Ey0\n' +
  'Q7/EKYk7KBMZfzRSyqsCIQDS56iq/5eiBztNGZh9CjuYZF88ipBGq1qltGNYB6qR\n' +
  'UwIgHGBFnFpNR2guS7+1/XcCDd/4EuofI0vhdLmPaJCXoM8CIQCUeumBMZ5UQRkb\n' +
  'x6hWZ6zbNdbirX6zchHIVT4XjJYl5wIgAYsoG+Y0sZx2cdGq4c1rth65WV6qdERw\n' +
  'A1imq+DZIzU='

// 加密
export const encrypt = (txt: string) => {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export const decrypt = (txt: string) => {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}
